package cn.stylefeng.guns.modular.gridsystem.timer;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.stylefeng.guns.core.timer.TimerTaskRunner;
import cn.stylefeng.guns.modular.gridsystem.entity.BizGateway;
import cn.stylefeng.guns.modular.gridsystem.entity.BizUploadScore;
import cn.stylefeng.guns.modular.gridsystem.service.BizGatewayService;
import cn.stylefeng.guns.modular.gridsystem.service.BizUploadScoreService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 定时删除30天之前上报的数据
 */
@Component
public class UploadScoreTaskRunner implements TimerTaskRunner {

    @Resource
    private BizUploadScoreService bizUploadScoreService;

    @Override
    public void action() {
        DateTime dateTime = DateUtil.offsetDay(new Date(), -30);
        LambdaQueryWrapper<BizUploadScore> wrapper = new LambdaQueryWrapper<>();
        wrapper.le(BizUploadScore::getCreatedAt, dateTime);
        bizUploadScoreService.remove(wrapper);
    }

}
